#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#define BUFSIZE 128


int main(int argc,char **argv)
{
	if (argc < 3)
	{
		fprintf(stderr,"Usage:%s\n",argv[0]);
		exit(1);
	}

	FILE *fps = NULL;
	FILE *fp = NULL;
	int fpd, fpc;
	char buf[BUFSIZE] = {0};

	fpd = open(argv[1],O_RDWR|O_APPEND,0666);
	if (fpd < 0)
	{
		perror("open()");
		exit(1);
	}
	fp = fopen(argv[2],"w+");
	if (fp == NULL)
	{
		perror("fopen()");	
		exit(1);
	}

//系统io转为标准io
	fps = fdopen(fpd,"r+");
//标准io转为系统io
	fpc = fileno(fp);	
	while (fgets(buf,BUFSIZE - 1,fps) != NULL)
	{
		write(fpc,buf,strlen(buf));
	}
	exit(0);
}
